package bTree.LeetCode;

public class Z字形变换 {
    public String convert(String s, int numRows) {
        if (numRows == 1) {
            return s;
        }
        String[] strings = new String[numRows];
        int path = 0;
        boolean ifAdd = true;
        for (int i = 0; i < s.length(); i++) {
            if (ifAdd) {
                strings[path] += s.charAt(i);
                path++;
                if (path == numRows) {
                    path -= 2;
                    ifAdd = false;
                }
            } else {
                strings[path] += s.charAt(i);
                path--;
                if (path == -1) {
                    path += 2;
                    ifAdd = true;
                }
            }
        }
        String res = "";
        for (String string : strings) {
            if (string != null) {
                res += string.substring(4);
            }
        }
        return res;
    }
}
